{include file="include/top"}
<body>
<div class="x-body">
    <form class="layui-form" action="javascript:;">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>规则名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$list.title}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>规则描述
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$list.name}">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>排序
            </label>
            <div class="layui-input-inline">
                <input type="number" id="condition" name="condition" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$list.condition}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>所属分类
            </label>
            <div class="layui-input-inline">
                <select id="pid" name="pid" class="valid">
                    {if $list.pid == 0}
                    <option value="0">父类</option>
                    {else}
                    {volist name="rule" id="ru"}
                    <option value="{$ru.id}" {if $ru.id == $list.pid} selected {/if}>{$ru.title}</option>
                    {/volist}
                    {/if}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" onclick="return edit()">
                保存
            </button>
        </div>
        <input type="hidden" id="id" value="{$list.id}" />
</form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
    });
    function edit()
    {
        var name = $("#name").val();
        var title = $("#title").val();
        var pid = $("#pid").val();
        var condition = $("#condition").val();
        var id = $("#id").val();
        var loading = layer.msg(0, {shade: false});
        $.ajax({
            type: 'POST',
            url: '{:url("Rule/edit")}',
            data: {name: name,title:title,pid:pid,id:id,condition:condition},
            success: function (res) {
                if(res.code>0){
                    layer.msg(res.msg,{icon:1,time:1500});
                    setTimeout(function(){
                        window.parent.location.reload();
                    },1500);
                }else{
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }
            },
            error: function (res) {
                console.log(res.msg);
            },
        });
    }

</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>
